package net.chrisjrock.display 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author Christopher J. Rock
	 */
	public class HotToggle extends HotButton
	{
		protected var _toggleFrame:int = 1;
		
		public function HotToggle() 
		{
			super();
			updateToggleFrame();
		}
		
		override public function gotoAndStop(frame:Object, scene:String = null):void 
		{
			super.gotoAndStop(frame , scene);
			updateToggleFrame();
		}
		
		override protected function addListeners():void 
		{
			super.addListeners();
			addEventListener(MouseEvent.CLICK , clickHandler , false , 0 , true);
		}
		
		override protected function removeListeners():void 
		{
			super.removeListeners();
			removeEventListener(MouseEvent.CLICK , clickHandler);
		}
		
		protected function updateToggleFrame ():void
		{
			var child:DisplayObject = getChildByName("toggle");
			if (child is MovieClip)
			{
				if (_toggleFrame > MovieClip(child).totalFrames)
				{
					_toggleFrame = 1;
				}
				MovieClip(child).gotoAndStop(_toggleFrame);
				return ;
			}
			
			_toggleFrame = 1;
		}
		
		protected function clickHandler (event:MouseEvent):void
		{
			_toggleFrame++;
			updateToggleFrame();
		}
	}

}